package com.example.mobwe_project;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class BookDetails extends Activity {

	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_bookdetalis);
		
		Button open=(Button)findViewById(R.id.button1);
		Button cancel=(Button)findViewById(R.id.button2);
		
		open.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				goForward();
				
			}
		});
		
		cancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				goBack();
				
			}
		});
		
       Intent i=new Intent();
       
       Bundle bundle = getIntent().getExtras();
       if(bundle == null){
    	   return;
       }
     

       String bookId = getIntent().getExtras().getString("bookId");
       EbookCollection collection = new EbookCollection();
       Ebook ebook = collection.getEbookById( bookId );
       
       ImageView imagePreview=(ImageView)findViewById(R.id.full_image_view);
       AppFolder app = new AppFolder();
       String path = app.getFolder();
       File file = new File(path + "/" + ebook.getId() + ebook.getPreview());
       imagePreview.setImageDrawable(Drawable.createFromPath(file.getAbsolutePath())); 
              
       
       TextView title=(TextView)findViewById(R.id.textView1);
       title.setText( title.getText() + ": " + ebook.getTitle());
       
       TextView author=(TextView)findViewById(R.id.textView2);
       author.setText( author.getText() + ": " + ebook.getAuthor());
       
       TextView theme=(TextView)findViewById(R.id.textView3);
       theme.setText( theme.getText() + ": " + ebook.getTheme()); 
       
       TextView description=(TextView)findViewById(R.id.textView4);
       description.setText( description.getText() + ": " + ebook.getDescription());
       
       TextView language=(TextView)findViewById(R.id.textView5);
       language.setText( language.getText() + ": " + ebook.getLanguage());
          
	
	}

	protected void goBack() {
		Intent back=new Intent(this,MenuActivity.class);
		startActivity(back);
	}

	protected void goForward() {
		Intent go=new Intent(this,NextPage.class);
		startActivity(go);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_hello, menu);
		return true;
	}

}
